import 'package:flame/components.dart';
import 'package:flame/flame.dart';
import 'package:flutter/material.dart';
import 'package:freedom/page/mahjong/common/common_card.dart';

import '../util/user_location.dart';
import 'mahjong_context.dart';

/// 统一生成 卡牌
/// TBRL   出牌信息
class CardBuildUtil {
  static CommonCard leftExport(Vector2 point, int card,
      {Direction? pointTo, Vector2? size, bool handCard = false}) {
    var cardSize = size ?? MahjongContext().lrExportCardSize;
    return CommonCard(
        size: cardSize,
        cardCode: card,
        pointToDirection: pointTo,
        handCard: handCard,
        focusColor: const Color.fromARGB(104, 255, 217, 0),
        cardDirection: Direction.LEFT,
        drift: true,
        backgroundSrc: 'mahjong/user/left/export_background.png',
        position: point);
  }

  static CommonCard rightExport(Vector2 point, int card,
      {Direction? pointTo, Vector2? size, bool handCard = false}) {
    var cardSize = size ?? MahjongContext().lrExportCardSize;
    return CommonCard(
        size: cardSize,
        cardCode: card,
        pointToDirection: pointTo,
        focusColor: const Color.fromARGB(104, 255, 217, 0),
        cardDirection: Direction.RIGHT,
        handCard: handCard,
        drift: true,
        backgroundSrc: 'mahjong/user/right/export_background.png',
        position: point);
  }

  static CommonCard topExport(Vector2 point, int card,
      {Direction? pointTo, Vector2? size, bool handCard = false}) {
    return CommonCard(
        cardDirection: Direction.TOP,
        pointToDirection: pointTo,
        size: size ?? MahjongContext().topExportCardSize,
        focusColor: const Color.fromARGB(104, 255, 217, 0),
        cardCode: card,
        drift: true,
        handCard: handCard,
        backgroundSrc: 'mahjong/user/top/export_background.png',
        position: point);
  }

  static CommonCard bottomExport(Vector2 point, int card,
      {Direction? pointTo, Vector2? size, bool showTips = false}) {
    return CommonCard(
        cardDirection: Direction.BOTTOM,
        pointToDirection: pointTo,
        size: size ?? MahjongContext().exportCardSize,
        showTips: showTips,
        focusColor: const Color.fromARGB(104, 255, 217, 0),
        cardCode: card,
        drift: true,
        backgroundSrc: 'mahjong/user/bottom/export_background.png',
        position: point);
  }

  static PositionComponent btDarkExport(Vector2 point, {Vector2? size}) {
    return SpriteComponent(
        sprite:
            Sprite(Flame.images.fromCache("mahjong/user/bottom/export_up.png")),
        size: size ?? MahjongContext().exportCardSize,
        position: Vector2(point.x, point.y));
  }

  /// 这是一个翻转图片
  /// 请注意左右使用请翻转270才显示正常
  static PositionComponent rDarkExport(Vector2 point, {Vector2? size}) {
    return SpriteComponent(
        sprite:
            Sprite(Flame.images.fromCache("mahjong/user/right/dark_card.png")),
        size: size ?? MahjongContext().exportCardSize,
        position: Vector2(point.x, point.y));
  }

  static PositionComponent lDarkExport(Vector2 point, {Vector2? size}) {
    return SpriteComponent(
        sprite:
            Sprite(Flame.images.fromCache("mahjong/user/left/dark_card.png")),
        size: size ?? MahjongContext().exportCardSize,
        position: Vector2(point.x, point.y));
  }

  static CommonCard bottomHandCard(Vector2 point, int card,
      {CardClickFun? cardClick,
      bool showTips = false,
      bool isOnClick = true,
      bool handCard = true,
      Vector2? size,
      bool focus = false}) {
    size = size ?? MahjongContext().bottomHandCard;
    return CommonCard(
        cardDirection: Direction.BOTTOM,
        isOnClick: isOnClick,
        position: point,
        handCard: handCard,
        size: size,
        cardClick: cardClick,
        showTips: showTips,
        focus: focus,
        cardCode: card);
  }
}
